<?
include_once("../../../../config.php");
//引入所有子系统信息
include_once("../../../common/model/extender_import.php");
//引入系统设置
include_once("../../../common/model/setting.php");

$table = $table_Prefix . "task_comment";
//设置需要搜索的表格的前缀后缀
$_REQUEST['ai_user_id'] = $_REQUEST['user_id'];
$_REQUEST['ai_task_id'] = $_REQUEST['nid'];
$_REQUEST['ai_date'] = date('Y-m-d H:i:s');
$_REQUEST['ai_content'] = $_REQUEST['content'];
$_REQUEST['ai_notice_member'] = $_REQUEST['notice_member'];

unset($_REQUEST['nid']);

//插入留言
$path = ROOT_PATH_."/uploadfiles/";
$_REQUEST['ai_content'] = replace_base64_with_image($_REQUEST['ai_content'],$path);
$sql=insert_date($table,$_REQUEST);
$query = mysql_query($sql) or die ("error:".mysql_error());
mysql_close($con);


//循环通知人员


//$_REQUEST['notice_member']='71';

//对比执行人ID 不同就推送消息给新执行人
if($_REQUEST['notice_member'])
{
    $member_list=select_lines_all_items($table_Prefix."employee","","nid > 0","");
    $member_openid_list=transform_2darray_in_1darray_with_new_key($member_list,"nid","openid");

    //获取任务信息
    $task=select_one_line_all_items($table_Prefix."task","nid = '".$_REQUEST['ai_task_id']."'");


    $_notice_member=$_REQUEST['notice_member'];

    foreach ($_notice_member as $member)
    {
    //查询新执行人openid并推送
    $openid=$member_openid_list[$member];
    $tip = "任务中有写给你的新的留言，请查阅【".$task['title']."】";
    //统一设置一下在公众号中的访问地址
    $custom_url="https://oa.vanzetech.com/front/employee_center/view/task_detail.php?openid=".$openid."&nid=".$task['nid'];

      

    include_once ROOT_PATH_."/api/wechat_message/notice_task_changed.php";
    }



    //如果转换到审核状态，就通知审核人
}







//查询评论信息
$comment_info=select_one_line_all_items($table_Prefix."task_comment","task_id = '".$_REQUEST['ai_task_id']."'order by nid desc");

//查询人员信息
$employee_info=select_one_line_all_items($table_Prefix."employee","nid = '".$comment_info['user_id']."'");


$principal_list=select_lines_all_items($table_Prefix."employee","nid desc","","0");
$member_name_list=transform_2darray_in_1darray_with_new_key($principal_list,"nid",'name');

?>




<!-- 拼接HTML输出到前台 -->
<div class="item">
    <div class="left">
        <div class="img-box">
            <?php if($employee_info['photo']){ ?>
                <img src="../../../../../uploadfiles/<?php echo $employee_info['photo']?>">
            <?php }else{ ?>
                <img src="../../../../../uploadfiles/default.png">
            <?php } ?>
        </div>
    </div>
    <div class="right">
        <div class="layui-col-md12 head">
            <p class="name"><?php echo $employee_info['name']?></p>
            <p class="date"><?php echo $comment_info['date']?></p>
        </div>

        <?if($comment_info['notice_member']){?>
            <p class="notice_list">
                <span class="layui-badge layui-bg-green">通知</span>
                <?
                $_notice_member=explode(",",$comment_info['notice_member']);
                $_notice_member_read=explode(",",$comment_info['notice_member_read']);

                foreach ($_notice_member as $k=>$v){?>
                    <span class="layui-badge  <?if(in_array($v,$_notice_member_read)){echo "layui-bg-green";}?> "><?echo $member_name_list[$v]?></span>
                    <?;}?>
            </p>
            <?;}?>


        <div class="layui-col-md12 content">
            <?php echo $comment_info['content']?>
            <div class="img-group"></div>
        </div>
    </div>
</div>